<template>
  <div class="work-container">
    <van-tabs
      v-model="activeName"
      color="#1989fa"
      line-width="24px"
      line-height="4px"
      sticky
      @click="handleClick"
    >
      <van-tab
        title="待审核"
        name="first"
      >
      </van-tab>
      <van-tab
        title="已审核"
        name="second"
      >
      </van-tab>
    </van-tabs>
    <div class="job-list">
      <van-list
        v-model="loading"
        :finished="finished"
        finished-text="没有更多了"
        @load="load"
      >
        <van-cell
          v-for="(item, index) in list"
          :key="index"
          :title="selectDictLabel(dict.type.sl_db_src, item.source)"
          :value="item.receptionTime"
          :label="`报工人: ${item.presenterNick}`"
          @click="gotoDetail(item)"
        />
        <van-empty
          v-if="!(list.length || loading)"
          description="暂无数据"
        />
      </van-list>
    </div>
  </div>
</template>

<script>
import { Notify } from "vant";


import { listDbinfo } from "@/api/sl/dbinfo";

export default {
  name: "h5Job",
  components: {
    [Notify.Component.name]: Notify.Component,
  },
  dicts: ['sl_event_level', 'sl_event_type', 'sl_event_status','sl_db_src'],
  data() {
    return {
      activeName: "first",
      // 查询参数
      queryParams: {
        isDb: 0,
        pageNum: 1,
        pageSize: 999,
      },
      list: [],
      total: 0,
      finished: false,
      loading: false,
    };
  },
  computed: {},
  created() {
    //获取当前报工人信息
    // this.getRworkUserBase(this.$store.state.user.name);
    this.load();
  },
  methods: {
    handleClick() {
      this.list = [];
      this.queryParams.pageNum = 1;
      this.total = 0;
      this.finished = false;
      this.load();
    },
    load() {
      console.log(this.activeName);
      this.loading = true;
      if (this.activeName === 'first') {
        this.queryParams.isDb = 0;
      } else {
        this.queryParams.isDb = 1;
      }
      this.listDbinfo();
    },
    /** 查询报工单列表 */
    // http://localhost:1024/dev-api/sl/rfwork/list?pageNum=1&pageSize=10
    listDbinfo() {
      this.loading = true;
      if (!this.finished) {
        listDbinfo(this.queryParams).then((response) => {
          if (response.code === 200) {
            this.list = [...this.list, ...response.rows];
            this.total = response.total;
            this.loading = false;
            if (this.queryParams.pageNum * this.queryParams.pageSize < this.total) {
              this.finished = false;
              this.queryParams.pageNum += 1;
            } else {
              this.finished = true;
            }
          } else {
            Notify({ type: "danger", message: "出错了" });
          }
        });
      }
    },
    gotoDetail(item) {
      if (item.source === 'jjbg') {
        // 计件
        this.$router.push({ path: `/h5/dbinfo-jijian?dbId=${item.dbId}&source=${item.source}&sourceId=${item.sourceId}` })
      } else if(item.source==='lgbg'){
        // 零工
        this.$router.push({ path: `/h5/dbinfo-linggong?dbId=${item.dbId}&source=${item.source}&sourceId=${item.sourceId}` })
      } else {
        this.$router.push({ path: `/h5/dbinfo-event?dbId=${item.dbId}` })
      }
    }
  },
};
</script>

<style lang="scss" scoped>
.job-list {
  padding: 15px 15px 80px;
}
@media (max-width: 550px) {
}
</style>
